<template>
  <div>
    <el-dialog
      :close-on-click-modal="false"
      :visible="dialogVisible"
      title="设置阀值"
      width="50%"
      :before-close="handleClose"
    >
      <vab-query-form>
        <vab-query-form-right-panel :span="24">
          <el-form
            label-width="49px"
            :inline="true"
            :model="queryForm"
            @submit.native.prevent
          >
            <el-form-item label="类型">
              <el-select v-model="queryForm.Type" placeholder="请选择">
                <el-option
                  v-for="item in Types"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="直径">
              <el-select v-model="queryForm.Diameter" placeholder="请选择">
                <el-option
                  v-for="item in Diameters"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="R角">
              <el-select v-model="queryForm.Rangle" placeholder="请选择">
                <el-option
                  v-for="item in Rangles"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="刃长">
              <el-select v-model="queryForm.BladeLengt" placeholder="请选择">
                <el-option
                  v-for="item in BladeLengths"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="材质">
              <el-select v-model="queryForm.Material" placeholder="请选择">
                <el-option
                  v-for="item in Materials"
                  :key="item"
                  :label="item"
                  :value="item"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button
                icon="el-icon-search"
                type="primary"
                @click="queryData"
              >
                查询
              </el-button>
            </el-form-item>
          </el-form>
        </vab-query-form-right-panel>
      </vab-query-form>
      <el-table :data="list" style="width: 100%">
        <el-table-column label="类型" prop="Type" />
        <el-table-column label="直径" prop="Diameter" />
        <el-table-column label="R角" prop="Rangle" />
        <el-table-column label="刃长" prop="BladeLength" />
        <el-table-column label="材质" prop="Material" />
        <el-table-column label="阈值" prop="AlarmNum" />
        <el-table-column label="库存" prop="Num" />
        <el-table-column
          align="center"
          label="操作"
          show-overflow-tooltip
          width="100"
        >
          <template slot-scope="scope">
            <el-button text type="primary" @click="handFazhi(scope.row)">
              设置阈值
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page="queryForm.pageNo"
        :layout="layout"
        :page-size="queryForm.pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
      <template slot="footer">
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <!-- <template>
          <el-button type="primary" @click="submit">确认</el-button>
        </template> -->
        </span>
      </template>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :visible="dialogVisible1"
      title="设置"
      width="30%"
      :before-close="handleClose1"
    >
      <el-form :model="form" label-width="120px">
        <el-form-item label="报警阈值">
          <el-input v-model="form.AlarmNum" />
        </el-form-item>
      </el-form>
      <template slot="footer">
        <span class="dialog-footer">
          <el-button @click="dialogVisible1 = false">取消</el-button>
          <template>
            <el-button type="primary" @click="submit">确认</el-button>
          </template>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {
    SetThresholdList,
    SerachItemList,
    KnifeInfoThresholdNewly,
    AlarmKnifeInfoList,
  } from '@/api/material'
  export default {
    data() {
      return {
        form: {
          AlarmNum: '',
        },

        Types: [],
        BladeLengths: [],
        Diameters: [],
        Rangles: [],
        Materials: [],
        list: [],
        total: 0,
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          Type: '',
          Diameter: '',
          Rangle: '',
          BladeLength: '',
          Material: '',
        },

        layout: 'total, sizes, prev, pager, next, jumper',
        dialogVisible: false,
        dialogVisible1: false,
      }
    },
    mounted() {
      this.fetchData()
    },
    methods: {
      submit() {
        KnifeInfoThresholdNewly(this.form).then((res) => {
          this.$baseMessage('设置成功', 'success', 'vab-hey-message-success')
          this.dialogVisible1 = false
          this.fetchData()
        })
      },
      handFazhi(e) {
        console.log(e)
        this.form = e
        this.dialogVisible1 = true
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      show() {
        console.log('aaaaaaaaaaaaaaaaaaa')
        this.dialogVisible = true
        this.query()
        this.fetchData()
      },
      handleClose() {
        this.dialogVisible = false
      },
      handleClose1() {
        this.dialogVisible1 = false
      },
      query() {
        SerachItemList().then((res) => {
          this.Types = res.Types.filter((v) => v)
          this.BladeLengths = res.BladeLengths.filter((v) => v)
          this.Diameters = res.Diameters.filter((v) => v)
          this.Rangles = res.Rangles.filter((v) => v)
          this.Materials = res.Materials.filter((v) => v)
        })
      },
      queryData() {
        this.fetchData()
      },
      fetchData() {
        const params = {
          Index: this.getPage(this.queryForm.pageNo, this.queryForm.pageSize),
          Count: this.queryForm.pageSize,
          Type: this.queryForm.Type,
          Diameter: this.queryForm.Diameter,
          Rangle: this.queryForm.Rangle,
          BladeLength: this.queryForm.BladeLength,
          Material: this.queryForm.Material,
        }
        SetThresholdList(params).then((res) => {
          console.log(res)
          this.list = res.AlarmKnifeInfo
          this.total = res.TotalCount
        })
      },
    },
  }
</script>

<style lang="scss" scoped></style>
